<?php

namespace XWAM\Addon\POrgCustomer\Controller;

/**
 * CustomerController 类
 *
 * @since 1.0 <2015-12-5> SoChishun <14507247@qq.com> Added.
 */
class CustomerOverdueController extends AddonbaseController {
    /**
     * 获取客户列表搜索数据
     * @return array
     * @since 1.0 2014-12-30 by sutroon
     */
    function customer_list_get_search() {
        $search = $_GET;
        if (!empty($search['telphone'])) {
            $where['telphone'] = array('like', '%' . $search['tel']);
        }
        if (!empty($search['name'])) {
            $where['name'] = array('like', '%' . $search['name'] . '%');
        }
        if (!empty($search['serial_no'])) {
            $where['serial_no'] = $search['serial_no'];
        }
        if (!empty($search['buy_count'])) {
            $where['buy_count'] = array('GT', $search['buy_count']);
        }
        if (!empty($search['total_amount'])) {
            $where['total_amount'] = array('GT', $search['total_amount']);
        }
        if ($this->user_login_data['type_name']=='SEAT') {
            $where['user_name']=$this->user_login_data['user_name'];
        }
        return array('search' => $search, 'where' => $where);
    }

    // 客户列表
    public function customer_list() {
        $asearch_info = $this->customer_list_get_search();
        if (I('action') == 'export') {
            $list = M('t_porg_customer')->field("personalName as '客户姓名', telphone as '电话号码', address as '联系地址', serialNo as '客户编号', buyCount as '购买次数', cumulativeAmount as '累计消费', lastBuyTime as '上次购买时间', userName as '工号', createdTime as '创建时间'")->where($asearch_info['where'])->select();
            if (!$list) {
                $this->error('找不到符合条件的记录!');
            }
            sofn_excel_export($list);
        } else {
            $list = D('Common')->get_paging_list($asearch_info['where'], $show, array('ORDERBY' => 'id desc', 'PAGEPARAMS' => $asearch_info['search'], 'TABLE' => 't_porg_customer'));
            $this->assign('page', $show);
            $this->assign('list', $list);
            $this->assign('search', $asearch_info['search']);
            $this->display_cpp();
        }
    }
}
